package com.alan.product.issue.content;

import java.lang.reflect.Field;
import java.util.Objects;

public class EqualsTest {

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        test1();
        test2();
        test3();
    }

    private static void test1() {
        Integer a = 1;
        Integer b = 1;
        Integer c = 128;
        Integer d = 128;
        System.out.println(Objects.equals(a, b));
        System.out.println(Objects.equals(c, d));
    }

    private static void test2() {
        Integer a = null;
        Integer b = 2;
        int c = 2;
        System.out.println(Objects.equals(a, b));
        System.out.println(Objects.equals(a, c));
    }

    private static void test3() throws NoSuchFieldException, IllegalAccessException {
        String a = "123";
        String b = "123";
        String c = new String("123");
        System.out.println(Objects.equals(a, b));
        System.out.println(Objects.equals(a, c));

        System.out.println(System.identityHashCode(a));
        System.out.println(System.identityHashCode(b));
        System.out.println(System.identityHashCode(c));

        Field field = String.class.getDeclaredField("value");
        field.setAccessible(true);
        System.out.println(System.identityHashCode(field.get(a)));
        System.out.println(System.identityHashCode(field.get(b)));
        System.out.println(System.identityHashCode(field.get(c)));
    }

}
